#include "expense.h"
#include "ui_expense.h"
#include<QDebug>
#include<QDesktopWidget>
#include<QtSql/QSqlQuery>
//This class represents user with different options such as create new expense,view expense,category and reports
expense::expense(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::expense)
{

    ui->setupUi(this);
    QRect innersize=QApplication::desktop()->availableGeometry(this);
    //ui->listWidget->setGeometry(0,50,(innersize.width()),(innersize.height()));
    ui->scrollArea->setGeometry(0,0,(innersize.width()),(innersize.height()));

    ui->listWidget->setEditFocus(true);
    int fontSize=10;//(innersize.width()/30.0);

    item1=new QListWidgetItem("New Expense",ui->listWidget,QListWidgetItem::UserType);
    item1->setFont(QFont( "lucida", fontSize, QFont::Normal, FALSE ));

    item2=new QListWidgetItem("View Expense",ui->listWidget,QListWidgetItem::UserType);
    item2->setFont(QFont( "lucida", fontSize, QFont::Normal, FALSE ));

    item3=new QListWidgetItem("Categories",ui->listWidget,QListWidgetItem::UserType);
    item3->setFont(QFont( "lucida", fontSize, QFont::Normal, FALSE ));

    item4=new QListWidgetItem("Reports",ui->listWidget,QListWidgetItem::UserType);
    item4->setFont(QFont( "lucida", fontSize, QFont::Normal, FALSE ));

    QAction* backAction = new QAction( tr("Back"), this );
     backAction->setSoftKeyRole( QAction::NegativeSoftKey );
     connect(backAction, SIGNAL(triggered()), this, SLOT(back()));
     addAction( backAction );
   /*  if(db.db_connect())
     {
        if(db.db_expense_table())
        {
         QSqlQuery q;
         qDebug()<<"Created";
         if(q.exec("PRAGMA foreign_keys = ON;"))
             qDebug()<<"Activated";
        }
         db.db_close();
     }*/


}

expense::~expense()
{
    delete ui;
}
void expense::back()
{

   (new MainWindow)->show();

}
void expense::on_listWidget_itemActivated(QListWidgetItem* item)
{
    if(item==item1)
    {
        (new NewExpense)->show();
    }
    else if(item==item2)
    {
        (new ExpView)->show();
    }
    else if(item==item3)
    {
        (new CatSelect)->show();
    }
    else if(item==item4)
    {
        (new Reports)->show();
    }
}
